﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

/// <summary>
/// Summary description for QLKhachHang
/// </summary>
public class QLKhachHang
{
    DBConnection db = new DBConnection();
	public QLKhachHang()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable Load_KH()
    {
        string sql = "select tendn,tenkh,diachikh,sodt,nhomchucnang.macn,tenchucnang from khachhang,nhomchucnang where khachhang.macn=nhomchucnang.macn";
        return db.Get_data(sql);
    }
    public DataTable Delete_KH(string tendn)
    {
        string sql = "delete from khachhang where tendn=@tendn";
        SqlParameter p1 = new SqlParameter("@tendn", tendn);
        return db.Get_data(sql, p1);
    }
    public DataTable Update_KH(string tendn, string macn)
    {
        string sql = "update khachhang set macn=@macn where tendn=@tendn";
        SqlParameter p1 = new SqlParameter("@tendn", tendn);
        SqlParameter p2 = new SqlParameter("@macn", macn);
        return db.Get_data(sql, p1, p2);
    }

    public DataTable Load_ChucNang()
    {
        string sql = "select macn,tenchucnang from nhomchucnang";
        return db.Get_data(sql);
    }
    public string Layten(string tendn)
    {
        string sql = "select tendn from khachhang where tendn=@tendn";
        SqlParameter p1=new SqlParameter("@tendn",tendn);
        object kq= db.LayDuLieu(sql, p1);
        return kq.ToString();
    }
}

